#!/bin/bash

set -x -e

CURRENT_DIR=`pwd`
SOURCE_DIR=@CMAKE_SOURCE_DIR@
MYTMPDIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`

cd $MYTMPDIR
cp -a $SOURCE_DIR/templates/project_root_containers .
cd project_root_containers
./rename.sh TestProj Tst det
mkdir build
cd build
export SIMPATH=@SIMPATH@
export FAIRROOTPATH=@CMAKE_INSTALL_PREFIX@
cmake -DCMAKE_CXX_STANDARD=@CMAKE_CXX_STANDARD@ ..

if [ "$1" = "--double-configure" ]
then
    echo "*** Calling cmake configure again:"
    # Check if all the cache variables
    # are good for a reconfiguration step
    cmake -DCMAKE_CXX_STANDARD=@CMAKE_CXX_STANDARD@ ..
fi

make

if [ $? -eq 0 ]; then
    echo 'Test successful.'
fi

cd $CURRENT_DIR
rm -rf $MYTMPDIR

